<?php
require_once "MyRabbitMq.php";

use MyRabbitMq\MyRabbitMq;
use PhpAmqpLib\Exchange\AMQPExchangeType;
use \PhpAmqpLib\Message\AMQPMessage;

$queueName = "noAutoAckQueue";
$exchangeName = "noAutoExchange";
$routeKey = "noAutoRouteKey";

$rabbit = new MyRabbitMq();
$rabbit->setExchange($exchangeName, AMQPExchangeType::DIRECT, false, true, false);
$rabbit->setQueue($queueName, false, true, false, false);
$rabbit->bindQueueExchange($queueName, $exchangeName, $routeKey);
$ch = $rabbit->getChannel();
//开启限流，每次处理一条消息
$ch->basic_qos(0, 1, false);

//返回消费消息成功并且给消费成功的信息
$callback = function (AMQPMessage $message) {
    echo $message->getBody().PHP_EOL;
    $message->getChannel()->basic_ack($message->getDeliveryTag());
};

$rabbit->consume($queueName, $callback, "", false, false);

while ($ch->is_consuming()) {
    $ch->wait();
}

$rabbit->close();